package com.mind.ridge.controller;

import com.mind.ridge.service.front.AddressBookService;
import com.mind.ridge.utils.R;
import org.springframework.web.bind.annotation.*;
import com.mind.ridge.pojo.front.AddressBook;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author Mind
 */
@RestController
@RequestMapping("/addressBook")
public class AddressBookController {

    @Resource
    private AddressBookService addressBookService;

    @PutMapping("/default")
    public R<AddressBook> setDefaultAddress(@RequestBody AddressBook addressBook,
                                         HttpSession session) {
        return addressBookService.setDefaultAddress(addressBook, session);
    }

    @GetMapping("/list")
    public R<List<AddressBook>> list(HttpSession session) {
        return addressBookService.addressList(session);
    }

    @PostMapping
    public R<String> add(@RequestBody AddressBook addressBook,
                         HttpSession session) {
        return addressBookService.addAddress(addressBook, session);
    }

    @GetMapping("/default")
    public R<AddressBook> getDefaultAddress(HttpSession session){
        return addressBookService.getDefaultAddress(session);
    }

}
